package com.ruoyi.ctcx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ctcx.domain.TbInsuranceContractPremiumPlan;
import com.ruoyi.ctcx.service.ITbInsuranceContractPremiumPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保险合同回款计划Controller
 * 
 * @author ruoyi
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/insurance/plan")
public class TbInsuranceContractPremiumPlanController extends BaseController
{
    @Autowired
    private ITbInsuranceContractPremiumPlanService tbInsuranceContractPremiumPlanService;

    /**
     * 查询保险合同回款计划列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbInsuranceContractPremiumPlan tbInsuranceContractPremiumPlan)
    {
        startPage();
        List<TbInsuranceContractPremiumPlan> list = tbInsuranceContractPremiumPlanService.selectTbInsuranceContractPremiumPlanList(tbInsuranceContractPremiumPlan);
        return getDataTable(list);
    }

    /**
     * 导出保险合同回款计划列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:plan:export')")
    @Log(title = "保险合同回款计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbInsuranceContractPremiumPlan tbInsuranceContractPremiumPlan)
    {
        List<TbInsuranceContractPremiumPlan> list = tbInsuranceContractPremiumPlanService.selectTbInsuranceContractPremiumPlanList(tbInsuranceContractPremiumPlan);
        ExcelUtil<TbInsuranceContractPremiumPlan> util = new ExcelUtil<TbInsuranceContractPremiumPlan>(TbInsuranceContractPremiumPlan.class);
        util.exportExcel(response, list, "保险合同回款计划数据");
    }

    /**
     * 获取保险合同回款计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbInsuranceContractPremiumPlanService.selectTbInsuranceContractPremiumPlanById(id));
    }

    /**
     * 新增保险合同回款计划
     */
    @PreAuthorize("@ss.hasPermi('insurance:plan:add')")
    @Log(title = "保险合同回款计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbInsuranceContractPremiumPlan tbInsuranceContractPremiumPlan)
    {
        tbInsuranceContractPremiumPlan.setCreateBy(getUsername());
        return toAjax(tbInsuranceContractPremiumPlanService.insertTbInsuranceContractPremiumPlan(tbInsuranceContractPremiumPlan));
    }

    /**
     * 修改保险合同回款计划
     */
    @PreAuthorize("@ss.hasPermi('insurance:plan:edit')")
    @Log(title = "保险合同回款计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbInsuranceContractPremiumPlan tbInsuranceContractPremiumPlan)
    {
        tbInsuranceContractPremiumPlan.setUpdateBy(getUsername());
        return toAjax(tbInsuranceContractPremiumPlanService.updateTbInsuranceContractPremiumPlan(tbInsuranceContractPremiumPlan));
    }

    /**
     * 删除保险合同回款计划
     */
    @PreAuthorize("@ss.hasPermi('insurance:plan:remove')")
    @Log(title = "保险合同回款计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbInsuranceContractPremiumPlanService.deleteTbInsuranceContractPremiumPlanByIds(ids));
    }
}
